package net.borlis.errors.exceptions;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * @author alex@borlis.net
 */
public class ExceptionKeyMaster implements IExceptionKeyMaster {

    private String key;
    private String code;

    public ExceptionKeyMaster(String code, String key) {
        this.key = key;
        this.code = code;
    }

    @Override
    public String getKey() {
        return key;
    }

    public String getCode() {
        return code;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ExceptionKeyMaster) {
            ExceptionKeyMaster other = (ExceptionKeyMaster) obj;
            EqualsBuilder builder = new EqualsBuilder();
            builder.append(getKey(), other.getKey());
            builder.append(getCode(), other.getCode());
            return builder.isEquals();
        }
        return false;
    }

    @Override
    public int hashCode() {
        HashCodeBuilder builder = new HashCodeBuilder();
        builder.append(getKey());
        builder.append(getCode());
        return builder.toHashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append("code", getCode()).
                append("key", getKey()).
                toString();
    }

}
